using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Text.RegularExpressions;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Passport_confirm_email : Member, IRequiresSessionState
{
	protected HtmlHead Head1;
	protected UserControls_cmpy_Top Top1;
	protected Literal UserName;
	protected Literal OldEmail;
	protected TextBox NewEmail;
	protected RegularExpressionValidator RegularExpressionValidator1;
	protected RequiredFieldValidator RequiredFieldValidator1;
	protected Button ConfirmBtn;
	protected HiddenField H_Email;
	protected UserControls_CMYP_Foot Foot1;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_PreInit(object sender, EventArgs e)
	{
		try
		{
		}
		catch (Exception ex)
		{
			base.WriteTemErrMsg(ex.Message.ToString());
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.H_Email.Value = (this.OldEmail.Text = base.user.UserEmail);
			this.UserName.Text = base.user.UserName;
		}
	}
	protected void ConfirmBtn_Click(object sender, EventArgs e)
	{
		string text = this.NewEmail.Text.Trim();
		string pattern = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		if (!Regex.IsMatch(text, pattern))
		{
			this.WriteErrMsg("", "邮箱格式错误!", "/Passport/confirm_email.aspx");
		}
		UserBll userBll = new UserBll(this.conn);
		if (this.H_Email.Value != text && !userBll.CheckUserExist("Email", text))
		{
			string text2 = Text.MakePassword();
			string text3 = Text.Md5(text2);
			string text4 = this.config["MessageOfConfrimEmail"].ToString();
			string newValue = this.config["SiteUrl"].ToString();
			string text5 = this.config["SiteName"].ToString();
			string mailTitle = text5 + "Email绑定确认邮件";
			string text6 = text4.Replace("{$CheckNum$}", text2);
			text6 = text6.Replace("{$UserName$}", base.user.UserName);
			text6 = text6.Replace("{$SiteURL$}", newValue);
			text6 = text6.Replace("{$SiteName$}", text5);
			text6 = text6.Replace("{$Email$}", text);
			text6 = text6.Replace("{$InputTime$}", DateTime.Now.ToString());
			try
			{
				Email email = new Email();
				email.SendEmail("smtp.163.com", "vgomallshop@163.com", "vgoshop", "vgomallshop@163.com", text6, text, mailTitle);
				string sql = string.Concat(new object[]
				{
					"update HL_User set Email='",
					this.NewEmail.Text,
					"' where UserID= ",
					base.user.UserID
				});
				int num = this.conn.Execute(sql);
				if (this.config["HLIntegration"].ToString() == "1")
				{
					new Integrate(this.conn)
					{
						ComeUrl = Fetch.CurrentUrl,
						sendEnd = "<script>alert('" + Language.Get("Common/Success") + "');top.location.href='{#GoUrl#}';</script>"
					}.Send("Modify", base.user.UserName, base.user.Password, text, "", "", 0, "", "");
				}
				else
				{
					this.WriteSuccessMsg("", "修改成功!", "../Member/Index.aspx?mainurl=Shop_UserInfoList.aspx");
				}
			}
			catch (Exception ex)
			{
				ex.WriteErrorLog(new string[0]);
			}
		}
		else
		{
			if (text == this.H_Email.Value)
			{
				this.WriteErrMsg("", Language.Get("PassPort/EmailExist"), "/Passport/confirm_email.aspx");
			}
		}
	}
}
